// JavaScript Document
var figureDocId = "";
var headPicInfoArr = [];
var meetingId = "";



function initHeadPic() {
	if(headPicInfoArr.length != 0){
		var imgFiguresDoc = document.getElementById("imgFigures");
		var figureDoc = document.createElement("figure");
		figureDocId = "figure" + headPicInfoArr[0].employeeId;
		figureDoc.id = figureDocId;
		var imgDoc = document.createElement("img");
		imgDoc.width = 72;
		imgDoc.height = 72;
		if(headPicInfoArr[0].url != null && headPicInfoArr[0].url != ''){
			imgDoc.src = headPicInfoArr[0].url;
		}
		var figcaptionDoc = document.createElement("figcaption");
		figcaptionDoc.innerHTML = headPicInfoArr[0].employeeName;
		figureDoc.appendChild(imgDoc);
		figureDoc.appendChild(figcaptionDoc);
		figureDoc.setAttribute("style", "transform:translate(-50px,-160px) scale(2.5);");
		imgFiguresDoc.appendChild(figureDoc);
		document.getElementById("welcomeAudio").play();
		setTimeout(changeHeadPic, 3000);
	} else {
		setTimeout(initHeadPic, 1000);
	}
}

function changeHeadPic() {
	var figureEle = document.getElementById(figureDocId);
	figureEle.setAttribute("style", "transform:translate(0px,0px) scale(1);transition-duration:1s;transition-deplay:2s;");
	for(var i = 0; i < headPicInfoArr.length; i++){
		if(i == (headPicInfoArr.length - 1)){
			headPicInfoArr.pop();	
		} else {
			headPicInfoArr[i] = headPicInfoArr[i + 1];
		}
	}
	setTimeout(initHeadPic, 3000);
}

function init(){
	meetingId = document.getElementById("meetingId").getAttribute("value");
	document.getElementById("welcomeAudio").playbackRate = 3.0;
	setTimeout(initHeadPic, 1000);
}

window.onload = init;

var interval1 = setInterval(function(){	
	$.ajax({
		type : "post",
		dataType:"json",
		url:"http://120.25.120.99:8080/YGJ/annualMeetingAction!getUnCheckAnnualMeetingRecord.action?async=y&meetingId=" + meetingId,
		success: function(data){
			if(data != null && data != ''){
				
				if(data.code == 1){
					
					if(data.result != null && data.result.length > 0){
						var result = data.result;
						/*alert(" employeeName: " + result[0].employeeId + " employeeName: " + result[0].employeeName + " meetingSignRecordId: " + result[0].meetingSignRecordId + " url: " + result[0].url);*/
						for(var i = 0; i < result.length; i++){
							headPicInfoArr.push(result[i]);
						}
					}
				}  
			}
		}	
	});
},3000);


function GetDateDiff(startTime, endTime, diffType) {
    //将xxxx-xx-xx的时间格式，转换为 xxxx/xx/xx的格式
    //startTime = startTime.replace(/\-/g, "/");
    //endTime = endTime.replace(/\-/g, "/");
    //将计算间隔类性字符转换为小写
    diffType = diffType.toLowerCase();
    //var sTime = new Date(startTime);      //开始时间
    //var eTime = new Date(endTime);  //结束时间
	var sTime = startTime;
	var eTime = endTime;
    //作为除数的数字
    var divNum = 1;
    switch (diffType) {
        case "second":
            divNum = 1000;
            break;
        case "minute":
            divNum = 1000 * 60;
            break;
        case "hour":
            divNum = 1000 * 3600;
            break;
        case "day":
            divNum = 1000 * 3600 * 24;
            break;
        default:
            break;
    }
    return parseInt((eTime.getTime() - sTime.getTime()) / parseInt(divNum));
}